main() {
  // 购物车数据
  List<Map> goodsList = [
    {
      "id": 1,
      "price": 22.68,
      "count": 3,
      "goods_name": "西瓜",
      "selectd": true,
    },
    {
      "id": 2,
      "price": 11.99,
      "count": 3,
      "goods_name": "草莓",
      "selectd": true,
    },
    {
      "id": 3,
      "price": 60.99,
      "count": 1,
      "goods_name": "车厘子",
      "selectd": false,
    },
    {
      "id": 4,
      "price": 11.68,
      "count": 3,
      "goods_name": "平谷大桃",
      "selectd": false,
    }
  ];
  //1. 计算选中商品的总价格
  double totalPrice = 0;
  for (var goods in goodsList) {
    if (goods["selectd"]) {
      totalPrice += goods["price"] * goods["count"];
    }
  }
  print("选中商品的总价格: ${totalPrice.toStringAsFixed(2)}");

//2. 使用for in
  for (var goods in goodsList) {
    if (goods["selectd"]) {
      totalPrice += goods["price"] * goods["count"];
    }
  }
  print("选中商品的总价格: ${totalPrice.toStringAsFixed(2)}");

  //3. 使用forEach
  goodsList.forEach((goods) {
    if (goods["selectd"]) {
      totalPrice += goods["price"] * goods["count"];
    }
  });
  print("选中商品的总价格: ${totalPrice.toStringAsFixed(2)}");
}
